# $Id: PKGBUILD 86603 2013-03-20 15:10:14Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Uroš Vampl <mobile.leecher at gmail dot com>

pkgname=tigervnc
pkgver=1.2.0
pkgrel=12
_xorgver=1.14.0
pkgdesc="suite of VNC servers and clients. VNC 4 branch of TightVNC."
arch=('i686' 'x86_64')
url="http://www.tigervnc.org"
license=('GPL')
depends=('pam' 'gnutls' 'libjpeg-turbo' 'libxft' 'libxinerama' 'libxcursor'
	 'libxtst' 'libxfont' 'pixman' 'xorg-xauth' 'xorg-xsetroot'
	 'xkeyboard-config' 'libgl' 'libgcrypt' 'perl')
makedepends=('cmake' 'nasm' 'xorg-font-util' 'xorg-util-macros' 'bigreqsproto'
	     'compositeproto' 'damageproto' 'randrproto' 'resourceproto'
	     'scrnsaverproto' 'videoproto' 'xcmiscproto' 'xf86vidmodeproto'
	     'xtrans' 'mesa' 'glproto' 'dri2proto' 'imagemagick' 'librsvg')
options=(!libtool)
conflicts=('tightvnc')
source=(http://downloads.sourceforge.net/tigervnc/${pkgname}-${pkgver}.tar.gz
	ftp://ftp.freedesktop.org/pub/xorg/individual/xserver/xorg-server-${_xorgver}.tar.bz2
	vncserver.service
	vncviewer.desktop
	xorg111.patch
	xorg112.patch
	xorg113.patch
	xorg114.patch
	xserver113.patch
	xserver114.patch
	glx.patch
	gnutls.patch
	gethomedir.patch
	cmakelists.patch)
md5sums=('3a5755b4ed600a81c3a17976c6f8420d'
         '86110278b784e279381b7f6f2295c508'
         '0903d5a0dfa38e0b04964505b644585c'
         '15c0405f920c3dac250692e8922578d1'
         'b680b55f7f9f569cd26ac0b330012a8b'
         'f73e055153889ae7b5aac8e697f7a841'
         'ef4078ba31a583dc3134e9090fbd30d0'
         '72518a7a1e7d3721ebe7404dcd8b3d01'
         'fabbe561d4ac845317ffdbf1bb2eeb02'
         '928faf837ba5b1b34283f9f018df2f5e'
         '4b86c015c78a0360205fdcf511ea1c39'
         '1a5fe8867ab3e49e20aafc70c415494f'
         'fa059baabe72308bf82622bca73cb3e0'
         '6ef923c71cc0e79c4b37eb3b124eea75')

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  cp -r ${srcdir}/xorg-server-${_xorgver}/* unix/xserver
  patch -Np1 -i ${srcdir}/gnutls.patch
  patch -Np1 -i ${srcdir}/gethomedir.patch
  patch -Np1 -i ${srcdir}/cmakelists.patch
  patch -Np1 -i ${srcdir}/xorg111.patch
  patch -Np1 -i ${srcdir}/xorg112.patch
  patch -Np1 -i ${srcdir}/xorg113.patch
  patch -Np1 -i ${srcdir}/xorg114.patch
  patch -Np1 -i ${srcdir}/glx.patch

  cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DUSE_INCLUDED_FLTK=yes
  make
  make -C media

  cd unix/xserver
  patch -Np1 -i ${srcdir}/xserver114.patch
  autoreconf -fiv
  ./configure --prefix=/usr \
	--disable-static --disable-xinerama --without-dtrace \
	--disable-xorg --disable-xnest --disable-xvfb --disable-dmx \
	--disable-xwin --disable-xephyr --disable-kdrive --with-pic \
	--disable-config-dbus --disable-config-hal --disable-config-udev \
	--disable-unit-tests --disable-devel-docs --disable-selective-werror \
	--disable-dri --enable-dri2 --enable-glx --enable-glx-tls
  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
  cd unix/xserver/hw/vnc
  make DESTDIR=${pkgdir} install
  sed -i 's/iconic/nowin/' ${pkgdir}/usr/bin/vncserver
  install -Dm0644 $srcdir/vncserver.service $pkgdir/usr/lib/systemd/system/vncserver.service
  install -dm0755 $pkgdir/usr/share/icons
  install -m0644 ${srcdir}/${pkgname}-${pkgver}/media/icons/* $pkgdir/usr/share/icons/
  install -Dm0644 $srcdir/vncviewer.desktop $pkgdir/usr/share/applications/vncviewer.desktop
}
